<!DOCTYPE html>
<html lang="en">
<head>
    <title>电子票待查确认</title>
    <#include "../inc/header.ftl"/>
    <link rel="stylesheet" href="${prefix}/assets/custom/css/main.css" />
</head>

<body class="no-skin">

<div class="main-container ace-save-state" id="main-container">

    <div class="main-content">
        <div class="main-content-inner">

            <div class="page-content">
                <table width="800" border="0" align="center" cellpadding="0" cellspacing="0" class="r_tablebr">
                    <tr>
                        <td class="r_nr">
                            <table width="99%" border="0" cellspacing="0" cellpadding="0">
                                <tr>
                                    <td class="r_title">河北省非税收入一般缴款书</td>
                                </tr>
                            </table>
                            <form name="ChargeBillForm" id="ChargeBillForm" action="" method="post">
                                <input name="filldate" type="hidden" id="filldate" value=""/>
                                <input name="waitaffirmid" type="hidden" id="waitaffirmid" value=""/>
                                <input name="paybankdt1" type="hidden" id="paybankdt1" value=""/>
                                <input name="payer1" type="hidden" id="payer1" value=""/>
                                <input name="accountcode1" type="hidden" id="accountcode1" value=""/>
                                <input name="originfund1" type="hidden" id="originfund1" value=""/>
                                <input name="bankaffirm1" type="hidden" id="bankaffirm1" value=""/>
                                <input name="eticketnum" type="hidden" id="eticketnum" value=""/>
                                <table width="99%" border="0" cellpadding="0" cellspacing="0" class="r_zsdwbm">
                                    <tr>
                                        <td>执收单位编码：
                                            <input name="unitcode" type="text" id="unitcode" readonly="readonly" value="" class="r_input" />          <label for="textfield"></label></td>
                                        <td colspan="2" align="right"><b>N0</b>
                                            <input name="billnum" type="text" id="billnum" value="" class="r_input2" style="width:110px;" />&nbsp;&nbsp;<input type="button" name="button1" id="button1" class="r_button" onclick="queryWaitaffirmData()" value="查询单据" />
                                        </td>
                                    </tr>
                                    <tr>
                                        <td width="40%">执收单位名称：
                                            <input name="unitname" type="text" id="unitname" readonly="readonly" style="width:230px" value="" class="r_input" /></td>
                                        <td width="20%" align="center" class="r_zsdwbmwz">开票日期：<span id="filldateshow">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></td>
                                        <td width="20%" align="left" class="r_zsdwbmwz">过期日期：<span id="guoqidateshow">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></td>
                                    </tr>
                                </table>
                                <table width="99%" border="1" cellpadding="0" cellspacing="1" class="r_jcxx2">
                                    <tr>
                                        <td width="15%" align="right">付款人全称</td>
                                        <td width="35%"><input name="payer" type="text" id="payer" readonly="readonly" style="width:95%" value="" /></td>
                                        <td width="15%" align="right">收款人全称</td>
                                        <td width="35%"><input name="payee" type="text" id="payee" readonly="readonly" style="width:95%" value="" /></td>
                                    </tr>
                                    <tr>
                                        <td align="right">付款人账号</td>
                                        <td><input type="text" name="payeraccount" id="payeraccount" readonly="readonly" value="" style="width:95%" /></td>
                                        <td width="15%" align="right">收款人账号</td>
                                        <td><input name="payeeaccount" type="text" id="payeeaccount" readonly="readonly" style="width:95%" value="" /></td>
                                    </tr>
                                    <tr>
                                        <td align="right">付款人开户银行</td>
                                        <td><input type="text" name="payerbank" id="payerbank" value="" readonly="readonly" style="width:95%" /></td>
                                        <td width="15%" align="right">收款人开户银行</td>
                                        <td><input name="payeebank" type="text" id="payeebank" style="width:95%" readonly="readonly" value="" /></td>
                                    </tr>
                                </table>
                                <table width="99%" border="1" cellpadding="0" cellspacing="1" class="r_jcxx" id="tab">
                                    <tr>
                                        <td width="10%" align="center">编码</td>
                                        <td width="40%" align="center">收入项目</td>
                                        <td width="10%" align="center">数量</td>
                                        <td width="20%" align="center">收缴标准</td>
                                        <td width="10%" align="center">金额</td>
                                    </tr>
                                    <tr id="tab-tr1">
                                        <td align="right">&nbsp;</td>
                                        <td>&nbsp;</td>
                                        <td width="15%" align="center">&nbsp;</td>
                                        <td align="center">&nbsp;</td>
                                        <td align="center">&nbsp;</td>
                                    </tr>
                                    <tr id="tab-tr2">
                                        <td align="right">&nbsp;</td>
                                        <td>&nbsp;</td>
                                        <td align="center">&nbsp;</td>
                                        <td align="center">&nbsp;</td>
                                        <td align="center">&nbsp;</td>
                                    </tr>
                                    <tr id="tab-tr3">
                                        <td align="right">&nbsp;</td>
                                        <td>&nbsp;</td>
                                        <td width="15%" align="center">&nbsp;</td>
                                        <td align="center">&nbsp;</td>
                                        <td align="center">&nbsp;</td>
                                    </tr>
                                </table>
                                <table width="99%" border="0" cellpadding="0" cellspacing="0" class="r_zsdwbm">
                                    <tr>
                                        <td width="110">校验码：
                                            <input name="vertifycode" type="hidden" id="vertifycode" class="r_input2" value="" />
                                            <input name="vertifycodeshow" type="text" id="vertifycodeshow" class="r_input2" style="width:40px" value="" />
                                        </td>
                                        <td width="160">付款方式：
                                            <input name="paywaycode" type="text" id="paywaycode" class="r_input2" style="width:80px"/></td>
                                        <td align="right">金额（大写）：
                                            <input name="bigoriginfund" type="text" id="bigoriginfund" readonly="readonly" class="r_input"style="width:220px" value="" />
                                            （小写）：
                                            <input name="originfund" type="text" id="originfund" readonly="readonly" class="r_input" style="width:100px" value="" /></td>
                                    </tr>
                                </table>
                            </form>
                            <table width="99%" border="0" cellpadding="0" cellspacing="0" class="r_zsdwbm">
                                <tr>
                                    <td align="left"><B>待查收确认</B></td>
                                    <td align="right"><input id="paybankdt" name="paybankdt" class="easyui-datebox" style="width:100px">
                                        <input type="button" name="waitbutton" id="waitbutton" class="r_button" onclick="regetWaitaffirm()" value="查询待查" />&nbsp;&nbsp;<input type="button" name="paybutton" id="paybutton"  class="r_button" onclick="pay()" value="确认" /></td>
                                </tr>
                            </table>
                            <table width="99%" border="1" cellspacing="1" cellpadding="0" class="r_dcsqr" id="tabx">
                                <tr>
                                    <td width="10%" align="center">付款人</td>
                                    <td width="20%" align="center">账号</td>
                                    <td width="20%" align="center">开户行</td>
                                    <td align="center">附言</td>
                                    <td align="center">交易流水</td>
                                    <td align="center">收款日期</td>
                                    <td align="center">电子票号</td>
                                </tr>

                                <tr id="tab-trx1">
                                    <td align="center">&nbsp;</td>
                                    <td align="center">&nbsp;</td>
                                    <td>&nbsp;</td>
                                    <td>&nbsp;</td>
                                    <td align="center">&nbsp;</td>
                                    <td align="center">&nbsp;</td>
                                    <td align="center">&nbsp;</td>
                                </tr>
                                <tr id="tab-trx2">
                                    <td align="center">&nbsp;</td>
                                    <td align="center">&nbsp;</td>
                                    <td>&nbsp;</td>
                                    <td>&nbsp;</td>
                                    <td align="center">&nbsp;</td>
                                    <td align="center">&nbsp;</td>
                                    <td align="center">&nbsp;</td>
                                </tr>
                                <tr id="tab-trx3">
                                    <td align="center">&nbsp;</td>
                                    <td align="center">&nbsp;</td>
                                    <td>&nbsp;</td>
                                    <td>&nbsp;</td>
                                    <td align="center">&nbsp;</td>
                                    <td align="center">&nbsp;</td>
                                    <td align="center">&nbsp;</td>
                                </tr>
                            </table>
                            <table width="99%" border="1" cellspacing="0" cellpadding="0">
                                <tr>

                                    <td height="40" align="right">
                                    </td>
                                </tr>
                            </table></td>
                    </tr>
                </table>
            </div><!-- /.page-content -->

        </div>
    </div><!-- /.main-content -->
</div><!-- /.main-container -->

<!-- basic scripts -->
<#include "../inc/basicjs.ftl"/>
<script src="${prefix}/assets/custom/js/commonview.js"></script>
<!-- inline scripts related to this page -->
<script type="text/javascript">

    $(function(){
        var curr_time = new Date();
        var str = curr_time.getFullYear()+"-";
        str += curr_time.getMonth()+1+"-";
        str += curr_time.getDate()+"-";
        $('#paybankdt').datebox('setValue',str);
    });
    //缴款方式下拉框
    $('#paywaycode').combobox({
        url:prefix + '/base/basedata/findPayWay',
        valueField:'paywayid',
        textField:'paywayname',
        panelHeight:'auto',
        onLoadSuccess:function(){
            var data = $('#paywaycode').combobox('getData');//获取所有下拉框数据
            if (data.length > 0) {
                //如果有数据的话默认选中第一条数据
                $('#paywaycode').combobox('select',data[0].paywayid);
            }
        }
    });

    //数据初始化
    var ischeck = false;
    function pay() {
        var vertifycode = $("#vertifycode").val();
        var paybankdt = $("#paybankdt1").val();
        var vertifycodeshow = $("#vertifycodeshow").val();
        if(vertifycode != vertifycodeshow){
            alert("校验码输入错误，请重新输入！");
            return;
        }
        var waitaffirmid = $("#waitaffirmid").val();
        if(waitaffirmid==""){
            alert("请选择付款人信息！");
        }else{
            $('#ChargeBillForm').form({
                url: prefix +'/view/waitaffirm/regetWaitaffirmPay',
                onSubmit:function(param){
                    param.paybankdt = paybankdt;
                    var isValid = $(this).form('validate');
                    if (isValid){
                        $.messager.progress({
                            title: '提示',
                            msg: '数据处理中，请稍候……',
                            text: ''
                        });
                    }
                    return isValid;
                },
                success:function(data) {
                    $.messager.progress('close');
                    var data = eval('(' + data + ')');
                    if(data.success) {
                        location=prefix+'/view/waitaffirm/rewaitaffirmview';
                    }
                    alert(data.msg);
                }
            });
            $('#ChargeBillForm').submit();
        }
    }
    function queryWaitaffirmData() {
        $("#waitaffirmid").val("");
        var billnum = $("#billnum").val();
        if(billnum=="") {
            alert("票据号不可为空！");
            $("#billnum").focus();
            return;
        }

        var state = [{"key":"0","value":"查询错误"},{"key":"1","value":"正常"},{"key":"2","value":"票据已用"},{"key":"3","value":"票据已核销"},{"key":"4","value":"票据不存在"},{"key":"5","value":"对账不成功，账户停用"},{"key":"6","value":"验签未通过"},{"key":"7","value":"该票据已超期"}];
        $.ajax({
            type: "POST",
            url: prefix+"/view/waitaffirm/queryWaitaffirmData",
            dataType: "json",
            data: { billnum: billnum},
            success: function (dataOne) {
                var data =new DOMParser().parseFromString(dataOne.data, "text/xml")
                $(data).find("bill").each(function(i) {     //查找所有student节点并遍历
                    var originfund = $(this).children("originfund");          //获得子节点
                    var originfund_vaule = originfund.text();                 //获取节点文本
                    $("#originfund").val(originfund_vaule);
                    $("#bigoriginfund").val(upDigit(originfund_vaule));
                    $("#billnum").val($(this).children("billnum").text());
                    $("#unitcode").val($(this).children("unitcode").text());
                    $("#unitname").val($(this).children("unitname").text());
                    $("#payer").val($(this).children("payer").text());
                    $("#payee").val($(this).children("payee").text());
                    $("#payeraccount").val($(this).children("payeraccount").text());
                    $("#payeeaccount").val($(this).children("payeeaccount").text());
                    $("#payerbank").val($(this).children("payerbank").text());
                    $("#payeebank").val($(this).children("payeebank").text());
                    $("#backbillnum").val($(this).children("backbillnum").text());
                    $("#vertifycode").val($(this).children("vertifycode").text());
                    var filldate = $(this).children("filldate").text();
                    $("#filldate").val(filldate);
                    $("#filldateshow").html(filldate);
                    $("#guoqidateshow").html(dateCount(filldate,10));
                    var billstate = $(this).children("billstate").text();
                    ischeck = true;
                    if(billstate!='1'){
                        $('#paybutton').attr('disabled',true);
                        $('#waitbutton').attr('disabled',true);
                        for(var p in state)
                        {
                            if(state[p].key==billstate)
                            {
                                alert(state[p].value);
                            }
                        }
                        return;
                    }else{
                        $('#paybutton').attr('disabled',false);
                        $('#waitbutton').attr('disabled',false);
                    }
                });
                var details_length = $(data).find("detail").length;
                if(details_length>0){
                    $("#tab-tr1").remove();
                    $("#tab-tr2").remove();
                    $("#tab-tr3").remove();
                    var rownum = 0;
                    var $tr = $("#tab tr:last");
                    var strhtml = "";
                    $(data).find("details").find("detail").each(function(index, ele) {
                        var itemcode = $(ele).find("itemcode").text();
                        var itemname = $(ele).find("itemname").text();
                        var amount = $(ele).find("amount").text();
                        var cityscale = $(ele).find("cityscale").text();
                        var originfund = $(ele).find("originfund").text();
                        strhtml = '<tr id="tab-tr'+(rownum+1)+'"><td align="center">'+itemcode+'</td><td>'+itemname+'</td><td width="15%" align="center">'+amount+'</td><td align="center">'+cityscale+'</td><td align="center">'+originfund+'</td></tr>';
                        $tr.after(strhtml);
                        rownum++;
                        $tr = $("#tab tr:last");
                    });
                    while(rownum<3){
                        strhtml = '<tr id="tab-tr'+(rownum+1)+'"><td align="center">&nbsp;</td><td>&nbsp;</td><td width="15%" align="center">&nbsp;</td><td align="center">&nbsp;</td><td align="center">&nbsp;</td></tr>';
                        $tr.after(strhtml);
                        rownum++;
                        $tr = $("#tab tr:last")
                    }
                }
            }
        })
    }

    function checkRadio(id) {
        $("#waitaffirmid").val(id);
        for(var p in dtl) {
            if(dtl[p].waitaffirmid==id) {
                $("#payer1").val(dtl[p].payer);
                $("#accountcode1").val(dtl[p].accountcode);
                $("#originfund1").val(dtl[p].originfund);
                $("#paybankdt1").val(dtl[p].paybankdt);
                $("#bankaffirm1").val(dtl[p].bankaffirm);
                $("#eticketnum").val(dtl[p].eticketnum);
            }
        }
    }
    var dtl = [];
    function regetWaitaffirm(){
        if(!ischeck) {
            alert("请先查询单据信息！");
            return;
        }
        dtl = [];
        var billnum = $("#billnum").val();
        var filldate = $("#filldate").val();
        var payeeaccount = $("#payeeaccount").val();
        var paybankdt = $("#paybankdt").val();
        var mainfund = $("#originfund").val();
        var nodata = true;
        $("#waitaffirmid").val("");
        $.ajax({
            type: "POST",
            url: prefix+"/view/waitaffirm/regetWaitaffirm",
            dataType: "json",
            data: { accountcode: payeeaccount,paybankdt:paybankdt,bankaffirm:''},
            success: function (dataOne) {
                var data =new DOMParser().parseFromString(dataOne.data, "text/xml")

                var bill_length = $(data).find("bill").length;
                if(bill_length>0){
                    var tLength = $("#tabx tr").length;
                    for(i=tLength-1;i>=1;i--) {
                        $("#tabx tr:eq("+i+")").remove();
                    }

                    var rownum = 0;
                    var $tr = $("#tabx tr:last");
                    var strhtml = "";
                    $(data).find("bills").find("bill").each(function(index, ele) {
                        var waitaffirmid = $(ele).find("waitaffirmid").text();
                        var cantonid = $(ele).find("cantonid").text();
                        var cantoncode = $(ele).find("cantoncode").text();
                        var cantonname = $(ele).find("cantonname").text();
                        var payer = $(ele).find("payer").text();
                        var payeraccount = $(ele).find("payeraccount").text();
                        var payerbank = $(ele).find("payerbank").text();
                        var billstate = $(ele).find("billstate").text();
                        var accountcode = $(ele).find("accountcode").text();
                        var bankaffirm = $(ele).find("bankaffirm").text();
                        var paybankdt = $(ele).find("paybankdt").text();
                        var bankid = $(ele).find("bankid").text();
                        var accountname = $(ele).find("accountname").text();
                        var bankname = $(ele).find("bankname").text();
                        var originfund = $(ele).find("originfund").text();
                        var eticketnum = $(ele).find("eticketnum").text();
                        var postscript = $(ele).find("postscript").text();
                        if(mainfund == originfund) {
                            dtl.push({"waitaffirmid":waitaffirmid,"billnum":billnum,"payer":payer,"filldate":filldate,"accountcode":accountcode,"originfund":originfund,"paybankdt":paybankdt,"bankaffirm":bankaffirm,"eticketnum":eticketnum});
                            strhtml = '<tr id="tab-trx'+(rownum+1)+'">'
                                +'<td align="center"><input type="radio" name="checkbox" id="checkbox" value="'+waitaffirmid+'" onclick="checkRadio(&quot;'+waitaffirmid+'&quot;)"/><label for="checkbox"></label>'+payer+'</td>'
                                +'<td align="center">'+payeraccount+'</td>'
                                +'<td>'+payerbank+'</td>'
                                +'<td>'+postscript+'</td>'
                                +'<td align="center">'+bankaffirm+'</td>'
                                +'<td align="center">'+paybankdt+'</td>'
                                +'<td align="center">'+eticketnum+'</td>'
                                +'</tr>';
                            $tr.after(strhtml);
                            rownum++;
                            $tr = $("#tabx tr:last");
                            nodata = false;
                        }
                    });
                    while(rownum<3) {
                        strhtml = '<tr id="tab-trx'+(rownum+1)+'">'
                            +'<td align="center">&nbsp;</td>'
                            +'<td align="center">&nbsp;</td>'
                            +'<td>&nbsp;</td>'
                            +'<td>&nbsp;</td>'
                            +'<td align="center">&nbsp;</td>'
                            +'<td align="center">&nbsp;</td>'
                            +'<td align="center">&nbsp;</td>'
                            +'</tr>';
                        $tr.after(strhtml);
                        rownum++;
                        $tr = $("#tabx tr:last")
                    }
                    if(nodata) {
                        alert("未查询到符合条件的数据！");
                    }
                }
                else {
                    alert("未查询到符合条件的数据！");
                }
            }
        });
    }
</script>
</body>
</html>
